package bpm.dao.user;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.user.OrgGroup;
import bpm.domain.user.OrgGroupType;
import bpm.domain.user.OrgUser;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class RankedOrgUserMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		OrgUser u = new OrgUser();
		
		u.setId(rs.getString("id"));
		u.setName(rs.getString("name"));
		u.setEmail(rs.getString("email"));
		u.setTel(rs.getString("tel"));
		u.setMobile(rs.getString("mobile"));
		String deptId = rs.getString("attr1");
		if(deptId != null) {
			u.setOrgGroup(new OrgGroup());
			u.getOrgGroup().setId(deptId);
		}
		u.setDeleteFlagString(rs.getString("attr2"));
		u.setLoginFlagString(rs.getString("attr3"));
		u.setCountString(rs.getString("attr4"));
		u.setLockFlagString(rs.getString("attr5"));
		
		String roleId = rs.getString("groupid");
		if(roleId != null) {
			OrgGroup role = new OrgGroup();
			role.setId(roleId);
			role.setGroupType(new OrgGroupType());
			role.getGroupType().setId(rs.getString("grouptypeid"));
			role.setSortIndex(rs.getInt("rank"));
			u.addGroup(role);
		}
		
		return u;
	}
}